package com.jjyu.controller;

import com.jjyu.entity.Result;
import com.jjyu.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/restaurants/favorites")
public class FavoritesController {
    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/add")
    public Result addFavorite(@RequestBody Map<String, String> params) {
        String userId = params.get("userId");
        String restaurantId = params.get("restaurantId");
        boolean isAdded = favoriteService.addFavorite(userId, restaurantId);
        if (isAdded) {
            return Result.success("收藏添加成功");
        } else {
            return Result.error("收藏添加失败");
        }
    }

    @GetMapping("/list")
    public Result listFavorites(@RequestParam String userId) {
        return Result.success(favoriteService.getFavoritesByUser(userId));
    }
}